//
//  TopicOtherTableViewCell.m
//  礼物go
//
//  Created by dllo on 16/5/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TopicOtherTableViewCell.h"
#import "TopicOtherCollectionViewCell.h"
#import "TopicOtherTDetailModel.h"

#define leftSpace 5
#define upSpace 5
#define labelHeight 20
#define ItemHeight 90

static NSString *const topicOtherCCell = @"otherCCell";

@interface TopicOtherTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,strong)UICollectionView *topicOtherCView;

@property(nonatomic,strong)UICollectionViewFlowLayout *flowLayout;



@end

@implementation TopicOtherTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.dataArray = [NSMutableArray array];
        self.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFAFA,0xBEBEBE);
        [self createSubviews];
    }
    return self;
}

-(void)createSubviews{
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(leftSpace * 2, upSpace, upSpace * 10, labelHeight)];
    //self.nameLabel.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.nameLabel];

   self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
//    self.flowLayout.itemSize = CGSizeMake((self.contentView.frame.size.width - 8 *leftSpace) / 4,(self.contentView.frame.size.height - self.nameLabel.frame.origin.y - self.nameLabel.frame.size.height - upSpace * 6) / 3);
    self.flowLayout.itemSize = CGSizeMake((self.contentView.frame.size.width - 14 *leftSpace) / 4,ItemHeight);
    self.flowLayout.sectionInset = UIEdgeInsetsMake(upSpace, leftSpace * 2, upSpace, leftSpace * 2);
    
self.topicOtherCView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height, SCREENWIDTH, self.contentView.frame.size.height - self.nameLabel.frame.origin.y - self.nameLabel.frame.size.height) collectionViewLayout:self.flowLayout];
    self.topicOtherCView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFAFA,0xBEBEBE);
    [self.contentView addSubview:self.topicOtherCView];
    self.topicOtherCView.delegate = self;
    self.topicOtherCView.dataSource = self;
    [self.topicOtherCView registerClass:[TopicOtherCollectionViewCell class] forCellWithReuseIdentifier:topicOtherCCell];
    self.topicOtherCView.bounces = NO;

}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.nameLabel.frame = CGRectMake(leftSpace * 2, upSpace, upSpace * 10, labelHeight);
//    self.flowLayout.itemSize = CGSizeMake((self.contentView.frame.size.width - 16 *leftSpace) / 4,(self.contentView.frame.size.height - self.nameLabel.frame.origin.y - self.nameLabel.frame.size.height - upSpace * 6) / 3);
    self.flowLayout.itemSize = CGSizeMake((self.contentView.frame.size.width - 14 *leftSpace) / 4,ItemHeight);
    self.topicOtherCView.frame = CGRectMake(0, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height, SCREENWIDTH, self.contentView.frame.size.height - self.nameLabel.frame.origin.y - self.nameLabel.frame.size.height);
}



-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TopicOtherTDetailModel *detailM = [self.dataArray objectAtIndex:indexPath.row];
    TopicOtherCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:topicOtherCCell forIndexPath:indexPath];
   // cell.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFAFA,0xBEBEBE);
    cell.detailModel = detailM;
    
    return cell;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
    
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  TopicOtherTDetailModel *detailM = [self.dataArray objectAtIndex:indexPath.row];
    self.PostColumnBlock(detailM.myId,detailM.name);
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
